home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 85 / CD Temático 40 Febrero 2004.iso / DOS / testdisk / src / geometry.c < prev    next >
Encoding:
C/C++ Source or Header  |  2004-01-09  |  3.3 KB  |  113 lines

  1. /*
  2.  
  3.     File: geometry.c
  4.  
  5.     Copyright (C) 1998-2004 Christophe GRENIER <grenier@cgsecurity.org>
  6.   
  7.     This software is free software; you can redistribute it and/or modify
  8.     it under the terms of the GNU General Public License as published by
  9.     the Free Software Foundation; either version 2 of the License, or
  10.     (at your option) any later version.
  11.   
  12.     This program is distributed in the hope that it will be useful,
  13.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15.     GNU General Public License for more details.
  16.   
  17.     You should have received a copy of the GNU General Public License
  18.     along with this program; if not, write to the Free Software
  19.     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  20.  
  21.  */
  22. #include <stdarg.h>
  23. #include <stdio.h>
  24. #include <stdlib.h>
  25. #include <string.h>
  26. #include <ctype.h>
  27. #include <unistd.h>    /* geteuid */
  28. #include "types.h"
  29. #include "common.h"
  30. #include "intrface.h"
  31.  
  32. void change_geometry(t_param_disk *disk_car)
  33. {
  34.   int done = FALSE;
  35.   char def[LINE_LENGTH];
  36.   char response[LINE_LENGTH];
  37.   int tmp_val;
  38.   int command;
  39.   int default_option=3;
  40.   int modified=0;
  41.  
  42.   while (done==FALSE) {
  43.     static struct MenuItem menuGeometry[]=
  44.     {
  45.       { 'c', "Cylinders", "Change cylinder geometry" },
  46.       { 'h', "Heads", "Change head geometry" },
  47.       { 's', "Sectors", "Change sector geometry" },
  48.       { 'd', "Done", "Done with changing geometry" },
  49.       { 0, NULL, NULL }
  50.     };
  51.     aff_copy_full(stdscr);
  52.     wmove(stdscr,5,0);
  53.     wdoprintf(stdscr,"%s",disk_car->description(disk_car));
  54.     wmove(stdscr,COMMAND_LINE_Y, COMMAND_LINE_X);
  55.     wclrtoeol(stdscr);
  56.     wrefresh(stdscr);
  57.     command=wmenuSimple(stdscr,menuGeometry, default_option);
  58.     command=toupper(command);
  59.     switch (command) {
  60.       case 'C':
  61.         sprintf(def, "%u", disk_car->CHS.cylinder+1);
  62.         mvwaddstr(stdscr,COMMAND_LINE_Y, COMMAND_LINE_X, "Enter the number of cylinders: ");
  63.         if (get_string(response, LINE_LENGTH, def) > 0) {
  64.           tmp_val = atoi(response);
  65.           if (tmp_val > 0 && tmp_val <= MAX_CYLINDERS) {
  66.             disk_car->CHS.cylinder = tmp_val-1;
  67.           } else
  68.             wdoprintf(stdscr,"Illegal cylinders value");
  69.         }
  70.         default_option=1;
  71.         modified=1;
  72.         break;
  73.       case 'H':
  74.         sprintf(def, "%u", disk_car->CHS.head+1);
  75.         mvwaddstr(stdscr,COMMAND_LINE_Y, COMMAND_LINE_X, "Enter the number of heads: ");
  76.         if (get_string(response, LINE_LENGTH, def) > 0) {
  77.           tmp_val = atoi(response);
  78.           if (tmp_val > 0 && tmp_val <= MAX_HEADS) {
  79.             disk_car->CHS.head = tmp_val-1;
  80.             if(modified==0)
  81.             {
  82.               disk_car->CHS.cylinder=(disk_car->size/(disk_car->CHS.head+1))/disk_car->CHS.sector-1;
  83.             }
  84.           } else
  85.             wdoprintf(stdscr,"Illegal heads value");
  86.         }
  87.         default_option=2;
  88.         break;
  89.       case 'S':
  90.         sprintf(def, "%u", disk_car->CHS.sector);
  91.         mvwaddstr(stdscr,COMMAND_LINE_Y, COMMAND_LINE_X, "Enter the number of sectors per track: ");
  92.         if (get_string(response, LINE_LENGTH, def) > 0) {
  93.           tmp_val = atoi(response);
  94.           if (tmp_val > 0 && tmp_val <= MAX_SECTORS) {
  95.             disk_car->CHS.sector = tmp_val;
  96.           } else
  97.             wdoprintf(stdscr,"Illegal sectors value");
  98.         }
  99.         default_option=3;
  100.         modified=1;
  101.         break;
  102.       case key_ESC:
  103.       case 'D':
  104. /*        case 'Q': */
  105.         done = TRUE;
  106.         break;
  107.     }
  108.   }
  109.   disk_car->size=(disk_car->CHS.cylinder+1)*(disk_car->CHS.head+1)*disk_car->CHS.sector;
  110.   ecrit_rapport("New geometry\n%s", disk_car->description(disk_car));
  111. }
  112.  
  113.